<template>
  <div>
    <Header></Header>
    <div class="archive-header">
      <div class="archive-header-inner h-v-30">
        <div class="bg-effect bg-poster poster-zoom"
          style="background-image:url('https://cosy.demo.nicetheme.xyz/style1/wp-content/uploads/sites/2/2020/08/2020082616501867.jpg')">
          <div class="overlay-1"></div>
        </div>
        <div class="archive-header-body px-3">
          <span class="btn btn-outline-light btn-xl btn-archive font-theme"><b class="h-1x">博客广场</b></span>
        </div>
      </div>
    </div>
    <div style="margin-top: 20px;">
      <el-row>
        <el-col :span="6">
          <div class="grid-content "></div>
        </el-col>
        <el-col :span="6">
          <div class="grid-content "></div>
        </el-col>
        <el-col :span="6">
          <el-input placeholder="请输入内容" prefix-icon="el-icon-search" @change="searchBlog(1)" v-model="search">
          </el-input>
        </el-col>
        <el-col :span="6">
          <div class="grid-content "></div>
        </el-col>
      </el-row>
    </div>
    <el-row>
      <el-col :span="5">
        <div class="grid-content"></div>
      </el-col>
      <el-col :span="14">
        <div style="margin-top:30px"></div>
        <el-row :gutter="20">
          <el-col v-for="blog in blogs" :key="blog.label" :span="6" style="margin-top:24px">
            <el-card shadow="hover" :body-style="{ padding: '0px' }" style="height:350px">
              <el-image :src="blog.image" class="image" style="width: 100%; height: 250px" fit="cover"></el-image>
              <div style="padding: 14px;">
                <el-link :href="'/blog/' + blog.id"> {{blog.title}}</el-link>
                <div class="bottom clearfix" style="position: relative;height:100%;">
                  <time class="time" style="position: absolute;bottom: 0px;">{{ blog.created }}</time>
                  <span style="float:right;font-size:0.95rem;color:#999">{{blog.username}}</span>
                </div>
              </div>
            </el-card>
          </el-col>

        </el-row>

        <div class="block" style="margin-top:48px">
          <el-pagination v-if="search == ''" class="mpage" background layout="prev, pager, next" :current-page="currentPage"
            :page-size="pageSize" :total="total" @current-change="page">
          </el-pagination>
          <el-pagination v-else class="mpage" background layout="prev, pager, next" :current-page="currentPage" :page-size="pageSize"
            :total="total" @current-change="searchBlog">
          </el-pagination>
        </div>

      </el-col>
      <el-col :span="5">
        <div class="grid-content"></div>
      </el-col>
    </el-row>

  </div>
</template>

<script>
import Header from "../components/Header";

export default {
  name: "Blogs.vue",
  components: { Header },
  data () {
    return {
      blogs: {},
      currentPage: 1,
      total: 0,
      pageSize: 16,
      search: ''
    }
  },
  methods: {
    page (currentPage) {
      const _this = this
      _this.$axios.get("/blogs?currentPage=" + currentPage).then(res => {
        console.log(res)
        _this.blogs = res.data.data.records
        _this.currentPage = res.data.data.current
        _this.total = res.data.data.total
        _this.pageSize = res.data.data.size
      })
    },
    searchBlog (currentPage) {
      const _this = this
      if (_this.search == '') {
        _this.page(1)
      } else {
        _this.$axios.get("/blog/search?context=" + _this.search + "&currentPage=" + currentPage).then(res => {
          console.log(res)
          _this.blogs = res.data.data.records
          _this.currentPage = res.data.data.current
          _this.total = res.data.data.total
          _this.pageSize = res.data.data.size
        })
      }
    }
  },
  created () {
    this.page(1)
  }
}
</script>

<style scoped>
.mpage {
  margin: 0 auto;
  text-align: center;
}
.time {
  font-size: 13px;
  color: #999;
}
a:hover {
  color: #0056b3;
  text-decoration: none;
}
.el-link.is-underline:hover:after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  bottom: 0;
  border-bottom: 0px solid #409eff;
}
.bottom {
  margin-top: 13px;
  line-height: 12px;
}

.button {
  padding: 0;
  float: right;
}

.image {
  width: 100%;
  display: block;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both;
}
.el-row {
  margin-bottom: 20px;
}
.el-col {
  border-radius: 4px;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}

.el-col {
  border-radius: 4px;
}
.bg-purple-dark {
  background: #99a9bf;
}
.bg-purple {
  background: #d3dce6;
}
.bg-purple-light {
  background: #e5e9f2;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}
*,
*::before,
*::after {
  -webkit-box-sizing: inherit;
  box-sizing: inherit;
  -webkit-font-smoothing: antialiased;
  word-break: break-word;
  word-wrap: break-word;
}

.archive-header-inner {
  position: relative;
  overflow: hidden;
  display: -webkit-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-box-flex: 1;
  -ms-flex: 1 1 auto;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  -webkit-align-items: center;
  align-items: center;
}
.h-v-30 {
  min-height: 30vh;
}

.poster-zoom {
  -webkit-animation: posterZoom 30s linear;
  animation: posterZoom 30s linear;
  -webkit-animation-fill-mode: forwards;
  animation-fill-mode: forwards;
}
.bg-poster {
  -ms-background-size: cover;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
}
.bg-effect {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}
.overlay-1 {
  width: 100%;
  height: 100%;
  background-color: rgba(22, 29, 39, 0.88);
  position: absolute;
  opacity: 0.4;
  top: 0;
  left: 0;
  -webkit-transition: opacity 0.3s ease-in-out;
  -o-transition: opacity 0.3s ease-in-out;
  transition: opacity 0.3s ease-in-out;
}
.archive-header-body {
  position: relative;
  z-index: 2;
}
.pl-3,
.px-3 {
  padding-left: 1rem !important;
}
.pr-3,
.px-3 {
  padding-right: 1rem !important;
}

.archive-header-body .btn-xl.btn-archive {
  min-width: 400px;
}
.archive-header-body .btn-xl.btn-archive {
  position: relative;
  background-color: transparent;
  background-image: none;
  border-color: #f4f4f5;
  color: #fff;
  font-size: 1.75rem;
  font-weight: bold;
  padding: 1rem;
  border-radius: 0;
  text-transform: uppercase;
  -webkit-transition: 1s all ease;
  -o-transition: 1s all ease;
  transition: 1s all ease;
}
.nice-style-radius .nav-links > span,
.nice-style-radius .nav-links > a,
.nice-style-radius .btn,
.nice-style-radius .form-control {
  border-radius: 5px;
}
.btn-outline-light {
  color: #515c67;
  background-color: #fff;
  background-image: none;
  border-color: #eeeeef;
}
.btn {
  border-radius: 2px;
  white-space: normal;
  font-size: 1rem;
  padding: 0.625rem 2rem;
}
.btn-outline-light {
  color: #f8f9fa;
  border-color: #f8f9fa;
}
.btn {
  display: inline-block;
  font-weight: 400;
  color: #212529;
  text-align: center;
  vertical-align: middle;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  background-color: transparent;
  border: 1px solid transparent;
  padding: 0.375rem 0.75rem;
  font-size: 1rem;
  line-height: 1.5;
  border-radius: 0.25rem;
  transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out,
    border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}
.font-theme {
  font-family: Manrope, "SF Pro SC", "SF Pro Text", Arial, sans-serif;
}
.archive-header-body .btn-xl.btn-archive::before {
  width: 0%;
  height: 100%;
}
.archive-header-body .btn-xl.btn-archive::before {
  background: #fff;
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  z-index: -1;
  -webkit-transition: all 0.6s ease;
  -o-transition: all 0.6s ease;
  transition: all 0.6s ease;
}
.archive-header-body .btn-xl.btn-archive b {
  position: relative;
  /* display: block; */
  z-index: 2;
  text-align: center;
  letter-spacing: 0.5em;
  text-indent: 0.5em;
}
.h-1x {
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}
b,
strong {
  font-weight: 700;
}
</style>